@extends('layouts.header')
@section('content')
<article class="page-container">
    <form class="form form-horizontal" id="form" autocomplete="off">
        <div class="row cl">
            <label class="form-label col-sm-3">属性：</label>
            <div class="formControls col-sm-4">
                <input name="name" type="text" class="input-text">
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-sm-3">状态：</label>
            <div class="formControls col-sm-9">
                <div class="skin-minimal">
                    <div class="radio-box">
                        <label><input type="radio" value="0" name="ishide">显示</label>
                    </div>
                    <div class="radio-box">
                        <label><input type="radio" value="1" name="ishide">隐藏</label>
                    </div>
                </div>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-sm-3">备注：</label>
            <div class="formControls col-sm-7">
                <textarea name="remark" class="input-text"></textarea>
            </div>
        </div>

        @csrf

        <div class="row cl pt-20">
            <div class="col-sm-9 col-sm-offset-3">
                <span class="btn btn-primary radius" id="submit"> 提 交 </span>
                <span class="btn btn-danger radius ml-15" onclick="layer_close();"> 取 消 </span>
            </div>
        </div>
    </form>

    <div class="page-container">
        <div class="mt-20">
            <table class="table table-border table-bordered table-hover table-bg table-responsive" id="datatable">
                <thead>
                    <tr class="text-c">
                        <th>属性</th>
                        <th>状态</th>
                        <th>备注</th>
                    </tr>
                </thead>
                <tbody id="tb-body">
                    @foreach ($list as $item)
                        <tr class="text-c">
                        <td>{{$item->name}}</td>
                        <td>{{$item->ishide ? "隐藏" : "显示"}}</td>
                        <td>{{$item->remark}}</td>
                    </tr>
                    @endforeach
                </tbody>
            </table>
        </div>
    </div>
</article>

<script type="text/javascript">
    var id;
    $(function(){
       id = {{request('id','')}}; 
       if(id == ""){
            layer_msg("请求出错啦！");
            layer_close();
       }
    })
    $('#submit').on('click',function () {
        
        ajax('post','namePlate/add?id='+id,$('#form').serialize(),submitBak,1);
        function submitBak(res){
            if(res == 1){
                $('#tb-body').append("<tr class='text-c'><td>"+$('[name=name]').val()+"</td><td>"+$('[name=ishide]').text()+"</td><td>"+$('[name=remark]').val()+"</td></tr>");
            }
        }
    })

</script>
@endsection